package com.base.controller;

import com.base.po.tbk.TbkBrandShop;
import com.base.service.LogsService;
import com.base.service.TbkBrandShopService;
import com.base.utils.Produce;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 添加精选专场
 */
@Controller
@RequestMapping("/admin")
public class add_TbkBrandShop {

	@Autowired
	private LogsService logsService;// log日志
	@Autowired
	private TbkBrandShopService tbkBrandShopService;

	// 添加分类
	@RequestMapping(value = "/toAddTbkBrandShop", method = RequestMethod.POST)
	public @ResponseBody int toAddTbkBrandShop(HttpServletRequest request, TbkBrandShop tbkBrandShop){
		String userid = (String) request.getSession().getAttribute("adminUserId"); // 登录的用户ID
		if (userid == null) return -1; // 未登录

		List<TbkBrandShop> tbkBrandShopList = tbkBrandShopService.selectByName(tbkBrandShop.getName());
		if (tbkBrandShopList != null && tbkBrandShopList.size() > 0){
			return -2;
		}

		tbkBrandShop.setId(Produce.getUUID());
		tbkBrandShop.setParentid(userid); // 代理商ID
		tbkBrandShop.setCreatetime(Produce.getNowDate()); // 创建时间
		tbkBrandShop.setDatastatus(1); // 状态可用
		return tbkBrandShopService.insertSelective(tbkBrandShop); // 添加
	}
}
